﻿using Ah.Testudin.Engine.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Ah.Testudin.Engine.Input
{
    public class MouseCursor : ICursor
    {
        #region Private Member Variables

        private int _x;

        private int _y;

        private int _cursorWidth;

        private int _cursorHeight;

        private Texture2D _cursorTexture;

        private ITestudinRenderer _renderer;

        #endregion

        #region Constructors

        public MouseCursor(
            int cursorWidth,
            int cursorHeight,
            Texture2D cursorTexture)
        {
            _cursorWidth = cursorWidth;

            _cursorHeight = cursorHeight;

            _cursorTexture = cursorTexture;

            _x = 0;

            _y = 0;

            _renderer = GraphicsDeviceRendererSingleton.Instance;
        }

        #endregion

        #region ICursor

        public Point Position
        {
            get
            {
                return new Point(
                    _x,
                    _y);
            }
        }

        public void Update()
        {
            MouseState mouseState = Mouse.GetState();

            _x = mouseState.X;

            _y = mouseState.Y;
        }

        public void Render()
        {
            _renderer.BeginSpriteBatch();

            _renderer.RenderSprite(
                new Rectangle(
                    _x,
                    _y,
                    _cursorWidth,
                    _cursorHeight),
                _cursorTexture);

            _renderer.EndSpriteBatch();

        }

        #endregion
    }
}
